package com.yanqu.road.server.cmd.activity.oldplayerreturn;

import com.yanqu.road.pb.activity.OldPlayerReturnProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.oldplayerreturn.OldPlayerReturnModule;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameProtocol;
import io.netty.channel.ChannelHandlerContext;

import java.util.List;

/**
 * @author ：zfr
 * @date ：2021/12/7 18:34
 */
@Cmd(code = GameProtocol.S_CROSS_GET_RETURN_ROLE_INFO_RESP, desc = "跨服返回回归角色信息")
public class CrossGetReturnRoleInfoRespCmd implements Command {
    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        OldPlayerReturnProto.GetOtherReturnInfoRespToServerMsg msg = OldPlayerReturnProto.GetOtherReturnInfoRespToServerMsg.parseFrom(packet.getBytes());
        long bindServerId = msg.getBindServerId();
        List<OldPlayerReturnProto.RoleUserInfoTemp> userInfos = msg.getUserInfoList();
        GamePlayer player = GamePlayerMgr.getOnlinePlayer(packet.getPlayerId());
        if (player != null) {
            player.getModule(OldPlayerReturnModule.class).syncRoleInfoResp(bindServerId, userInfos, msg.getCanReturnTime());
        }
    }
}
